<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>小练习2-JS进阶（二）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 小练习2：思考以下的代码运行结果，并说明为什么？

                    'use strict';
                    var a = 20;
                    function foo () {
                        var a = 1;
                        var obj = {
                            a: 10,
                            c: this.a + 20,
                            fn: function () {
                                return this.a;
                            }
                        }
                        return obj.c;

                    }
                    console.log(foo());    // 报错。foo独立调用，this在严格模式下指向undefined
                    console.log(window.foo());  // 40。foo为调用者函数，为window对象所拥有。
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/p_2.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>